﻿<Window x:Class="LockCrypt.WinAddTemplate"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:LockCrypt"
    xmlns:lex="http://schemas.root-project.org/xaml/presentation"
    xmlns:conv="clr-namespace:LockCrypt.Converters"
    xmlns:l49ui="clr-namespace:Lime49.UI;assembly=Lime49"
    xmlns:l49="clr-namespace:Lime49;assembly=Lime49"
    Title="{lex:LocText LockCrypt.Core:Strings:NewTemplate}" Style="{StaticResource {x:Type Window}}" Icon="/LockCrypt;component/Resources/LockCrypt.ico"
    MinHeight="250" MinWidth="100" Width="320" SizeToContent="Height"
    WindowStartupLocation="CenterOwner" Loaded="Window_Loaded" x:Name="root"
    l49:WindowService.EscapeClosesWindow="True">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" />
        <CommandBinding Command="ApplicationCommands.Delete" Executed="DeleteField"/>
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.New" Executed="AddField" />
        <!--CommandBinding Command="ApplicationCommands.Properties" Executed="RenameField"/-->
        <CommandBinding Command="ApplicationCommands.Save" Executed="Save" />
        <CommandBinding Command="NavigationCommands.GoToPage" Executed="MoveField" CanExecute="CanMoveField" />
        <CommandBinding Command="loc:LockCryptCommands.MarkAsUrl" Executed="MarkAsUrl" />
        <CommandBinding Command="loc:LockCryptCommands.MarkAsPassword" Executed="MarkAsPassword" />
        <CommandBinding Command="loc:LockCryptCommands.MarkAsPhone" Executed="MarkAsPhone" />
    </Window.CommandBindings>
    <Window.Resources>
        <BitmapImage x:Key="settings_16" UriSource="pack://application:,,,/Resources/Images/settings_16.png" x:Shared="true" />
        <conv:MetaFlagsToBoolConverter x:Key="metaConverter"/>
    </Window.Resources>
    <DockPanel Margin="6" LastChildFill="True">
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button x:Name="btnSave" MinWidth="70" IsDefault="True" Command="ApplicationCommands.Save" Content="{lex:LocText LockCrypt.Core:Strings:Save}" />
            <Button x:Name="btnCancel" MinWidth="70" IsCancel="True" Command="ApplicationCommands.Close" Content="{lex:LocText LockCrypt.Core:Strings:Cancel}"/>
        </StackPanel>
        <Grid DockPanel.Dock="Top" Grid.IsSharedSizeScope="True">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="labels" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Name}"/>
            <TextBox Grid.Row="0" Grid.Column="1" x:Name="txtName" TabIndex="1" Text="{Binding SelectedTemplate.Name,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

            <Label Grid.Row="1" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:ShowTheNotesField}"/>
            <CheckBox Grid.Row="1" Grid.Column="1" x:Name="chkShowNotes" TabIndex="2" IsChecked="{Binding SelectedTemplate.ShowNotes,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"  />
            
            <ListBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="lstFields" ItemsSource="{Binding SelectedTemplate.Fields,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=true}"
                     Style="{StaticResource InvisibleListBox}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBox x:Name="txtFieldName" Grid.Column="0" Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" 
                                     Style="{StaticResource MetaDataTextBox}" DataContext="{Binding}"/>
                            <l49ui:MenuButton Grid.Column="1" Width="20" Height="20" ToolTip="{lex:LocText LockCrypt.Core:Strings:Options}" MenuLocation="Right"
                                            AlwaysShowBorder="True" ShowArrow="False">
                                <l49ui:MenuButton.Content>
                                    <Image Source="{StaticResource settings_16}"/>
                                </l49ui:MenuButton.Content>
                                <l49ui:MenuButton.Menu>
                                    <ContextMenu>
                                        <!--MenuItem Header="{lex:LocText LockCrypt.Core:Strings:RenameField}" Command="ApplicationCommands.Properties" CommandTarget="{Binding DataContext,ElementName=txtFieldName,Mode=TwoWay}"/-->
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:DeleteField}" Command="ApplicationCommands.Delete" CommandTarget="{Binding ElementName=txtFieldName}"/>
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:MoveUp}" Command="NavigationCommands.GoToPage" CommandTarget="{Binding ElementName=txtFieldName}" CommandParameter="-1"/>
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:MoveDown}" Command="NavigationCommands.GoToPage" CommandTarget="{Binding ElementName=txtFieldName}" CommandParameter="1"/>
                                        <Separator/>
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:MarkAsUrl}" Command="loc:LockCryptCommands.MarkAsUrl" CommandTarget="{Binding ElementName=txtFieldName}"
                                                  DataContext="{Binding}" IsChecked="{Binding DataContext.Meta,RelativeSource={RelativeSource Self},Converter={StaticResource metaConverter},ConverterParameter=Url}"/>
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:MarkAsPassword}" Command="loc:LockCryptCommands.MarkAsPassword" CommandTarget="{Binding ElementName=txtFieldName}"
                                                  DataContext="{Binding}" IsChecked="{Binding DataContext.Meta,RelativeSource={RelativeSource Self},Converter={StaticResource metaConverter},ConverterParameter=Password}"/>
                                        <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:MarkAsPhoneNumber}" Command="loc:LockCryptCommands.MarkAsPhone" CommandTarget="{Binding ElementName=txtFieldName}"
                                                  DataContext="{Binding}" IsChecked="{Binding DataContext.Meta,RelativeSource={RelativeSource Self},Converter={StaticResource metaConverter},ConverterParameter=Phone}"/>
                                    </ContextMenu>
                                </l49ui:MenuButton.Menu>
                            </l49ui:MenuButton>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <StackPanel Grid.Row="3" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right">
                <l49ui:ImageButton Command="ApplicationCommands.New" Text="{lex:LocText LockCrypt.Core:Strings:AddField}" 
                                 Image="pack://application:,,,/Resources/Images/add_16.png" ImageLocation="Left" HorizontalAlignment="Right"/>
            </StackPanel>
        </Grid>
    </DockPanel>
</Window>
